@echo off

setlocal ENABLEDELAYEDEXPANSION

if "X%1" == "X" (
    echo Usage: %0 ^<pattern1^> ...^<pattern2^>.. ^<pattern6^>
    echo Pattern could be anything like folderName\*.c folder1\folder2\*.cpp Makefile
    @echo:
    echo E.G. "%0 prod\extn\*.cpp prod\extn\*h Makefile" 
    echo would open all the files which have file extn cpp and end with h in prod\extn folder also all the makefile's would be open w.r.t. the cwd in a single gvim file
    echo Advantage is all the open files can be accessed by using :b ^<name^>
    echo Also in :b vim command there's tab completion for opened file names
    echo :ls vim command lists the files which are opened and can be accessed using :b
    echo To open all files recursively from the current working directory, command would be %0 *
    echo Add %0 to the environment by appending the location of %0 to PATH variable
    exit /b -1
    )

echo Opening all files recursively from Current dir: %cd%
set TITLE=VIM%TIME%
start gvim --servername %TITLE%

for /f "tokens=1 delims=*" %%i in ('dir /s /b %1 %2 %3 %4 %5 %6') do echo "%%i"
ping localhost  -n 2 > NUL 2>NUL

echo Files to be opened in vim are:
for /f "tokens=1 delims=*" %%i in ('dir /s /b %1 %2 %3 %4 %5 %6') do gvim --servername %TITLE% --remote-send "<Esc>:e "%%i" <CR>"
